package com.cskaoyan.test;

import com.cskaoyan.MyConnectionPool;
import com.cskaoyan.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * 创建日期: 2022/04/25 22:16
 *
 * @author ciggar
 */
public class MyThread extends Thread{


    MyConnectionPool myConnectionPool;

    public void setMyConnectionPool(MyConnectionPool myConnectionPool) {
        this.myConnectionPool = myConnectionPool;
    }

    @Override
    public void run() {

        try {
            MyConnectionPool myConnectionPool = new MyConnectionPool();

            // 获取连接
            Connection connection = myConnectionPool.getConnection();


            Statement statement = connection.createStatement();

            ResultSet resultSet = statement.executeQuery("select * from account where id = 2");


            while (resultSet.next()) {

                String name = resultSet.getString("name");
                int id = resultSet.getInt("id");

                System.out.println("id:" + id + ", name:" + name);
            }


            // 关闭其他的资源 , 注意：连接一定不能关闭了之后再返回到数据库连接池
            JDBCUtils.close(connection, statement, resultSet);

        }catch (Exception ex) {
            ex.printStackTrace();
        }
    }


}
